package com.supeng.PMdepot.adapter.bak;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.supeng.PMdepot.R;
import com.supeng.PMdepot.common.Constant;
import com.supeng.PMdepot.entity.bak.been.ImageBeen;
import com.supeng.PMdepot.util.ImageLoaderUtil;

import java.util.List;

/**
 * Created by Supeng on 2018/8/23.
 */
//Caption been
public class AddBaoXiuAddAdapter  extends BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder> {
    public static final int TYPE_LEVEL_IMAGE = 0;
    public static final int TYPE_LEVEL_ADD= 2;
    public AddBaoXiuAddAdapter(List data) {
        super(data);
        addItemType(TYPE_LEVEL_IMAGE, R.layout.layout_add_baoxiu_item);
        addItemType(TYPE_LEVEL_ADD, R.layout.layout_add_baoxiu_add_item);
    }
    @Override
    protected void convert(final BaseViewHolder holder, MultiItemEntity itemTemp) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_IMAGE:
                final ImageBeen item= (ImageBeen) itemTemp;
                ImageLoaderUtil.loadImage(mContext, Constant.getBaseUrl()+item.getPath(),(ImageView) holder.getView(R.id.fiv));
                holder.getView(R.id.ll_del).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int index = holder.getAdapterPosition();
                        // 这里有时会返回-1造成数据下标越界,具体可参考getAdapterPosition()源码，
                        // 通过源码分析应该是bindViewHolder()暂未绘制完成导致，知道原因的也可联系我~感谢
                        if (index != RecyclerView.NO_POSITION) {
                            getData().remove(index);
                            notifyItemRemoved(index);
                            //notifyItemRangeChanged(index, getData().size());
                        }
                    }
                });
                break;
            case TYPE_LEVEL_ADD:
                holder.addOnClickListener(R.id.iv_add);
                break;
        }

    }
}
